package cs2340.todolist.model.sqlite_database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class UserAccountSQLiteHelper extends SQLiteOpenHelper {

	public static final String TABLE_USERS 		= "users";
	public static final String COLUMN_ID		= "_id";
	public static final String COLUMN_NAME 	 	= "name";
	public static final String COLUMN_EMAIL	 	= "email";
	public static final String COLUMN_USERNAME	= "username";
	public static final String COLUMN_PASSWORD	= "password";


	private static final String DATABASE_NAME = "todolist.db";
	private static final int DATABASE_VERSION = 1;

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_USERS 
				+ "( " 
				+ COLUMN_ID 			+ " integer primary key autoincrement, " 
				+ COLUMN_NAME 			+ " text not null,"
				+ COLUMN_EMAIL 			+ " text not null,"
				+ COLUMN_USERNAME		+ " text not null unique,"
				+ COLUMN_PASSWORD		+ " text not null"
				+ ");";
	
	/**
	 * gets all column names for the table
	 * @return the column names
	 */
	public static String[] getAllColumnNames() {
		String[] columnNames = {
				COLUMN_ID,
				COLUMN_NAME,
				COLUMN_EMAIL,
				COLUMN_USERNAME,
				COLUMN_PASSWORD
				};
		return columnNames;
	}

	/**
	 * constructer for this class
	 * @param context - context being used
	 */
	public UserAccountSQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}
	

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(UserAccountSQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS" + TABLE_USERS);
		onCreate(db);
	}

}
